Skip to content

Conversation

ayushb
Copy link
Member

@ayushb ayushb commented Sep 14, 2026

Builds on #23. Targets issue-6 rather than main so that PR is green before it merges.

npm run build currently fails on issue-6: tsc -b reports 14 errors and eslint . reports 6. This branch clears both without changing what the app is meant to do.

Blocking fixes

  • SORT_OPTIONS was deleted but isSortOption still called it, and sort was written with an unchecked as SortOption cast. Restored the constant and put the validation back, so a broken value in session storage resets that one field as the comment promises.
  • SortOption is now only id-asc and id-desc. Sorting by name would mean fetching every pokemon just to learn the names, which the fetch-on-the-fly rule does not allow.
  • GetMany pushed the result of fetchSafe straight into a PokemonData[], so a failed id put a null in the list and the favorites view crashed on it. It now fetches in parallel and drops the failures.
  • matchesFilter took one argument but was still called with two in GetPrevFiltered and GetNextFiltered. The rules are passed in as a parameter again, which also stops it re-reading session storage once per pokemon inside a loop that can run a thousand times.
  • FavoritePokemon called .sort() and onSelectPokemon() on props typed as optional. They are required now, and the sort copies first instead of mutating the caller's array.
  • Untyped index access in PokemonCard and filters.ts.
  • total was reassigned during render, which the react-hooks rules reject. It is a reduce now.

Behaviour fixes

  • Navigating to a new pokemon kept showing the previous one's sprite, because the sprite lived in useState and the card never remounts. It resets when the id changes.
  • PokemonList and useFavorites fetched with plain useState and useEffect. Both go through TanStack Query now, so the neighbours and favorites are cached instead of refetched on every click.
  • The favorite entries and the sprite toggle were div and li with onClick, so neither could be reached by keyboard. They are buttons with focus outlines.
  • App rendered a second id="root" inside the one in index.html. Replaced with .app-layout.

Checks

before after
tsc -b 14 errors clean
eslint . 6 errors clean
vitest run 34 passed 34 passed
vite build fails builds

PokemonList.test.tsx was removed in #23 and is not restored here, and GetNextFiltered / GetPrevFiltered still have no tests. Both are covered by #10.

* Restore SORT_OPTIONS and validate sort on load instead of casting it
* Limit SortOption to id-asc and id-desc, name sorting needs a full preload
* Pass filter rules into GetPrevFiltered and GetNextFiltered instead of
  reading session storage once per pokemon
* Fetch favorites in parallel and drop the ids that failed
* Reset PokemonCard to the default sprite when a new pokemon is shown
* Move PokemonList and useFavorites onto TanStack Query
* Render favorite entries and the sprite toggle as buttons for keyboard access
* Replace the duplicate id="root" wrapper with .app-layout
* Add a shared QueryClient wrapper for hook and component tests

References #6
@ayushb
Copy link
Member Author

ayushb commented Sep 15, 2026

Rolled this into #26 together with the filter branch so it's one review instead of a stack of three. Same commits, nothing dropped.

@ayushb ayushb closed this Sep 15, 2026
@thomhet thomhet deleted the fix/issue-6-build-errors branch September 18, 2026 22:58
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant